<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正则表达式</title>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    console.log("------search------") //search寻找搜索
    let str = "hello kgc"
    console.log(str.search(/kgc/)) //6
    console.log(str.search(/KGC/)) //-1
    console.log(str.search(/KGC/i)) //6
    console.log("------match------") //match检索字符串
    let str1 = "1 and 2 and 3"
    console.log(str1.match(/\d/)) //[1]
    console.log(str1.match(/kgc/)) //null
    console.log(str1.match(/\d/g)) //["1"'2''3']
    //replace替换
    console.log("-----------replace-------------")
    let str2 = "hello kgc！ hello kgc!"
    console.log(str2.replace(/kgc/g, "web19")) //"hello web19！ hello web19!"
    //split分割
    console.log("-----------split-------------")
    let str3 = "hello kgc！ hello kgc!"
    //分割后保存4个元素
    console.log(str3.split(/kgc/, 4))
</script>

</html>